x = int(input())
if 1000 <= x < 10000:
    z = 0
    y = []
    for i1 in range(0, 4, 1):
        for i2 in range(i1+1, 5, 1):
            y = x % 10**i2 // 10**i1
            if not y in [0, 1]:
                for i in range(2, y, 1):
                    if y % i == 0:
                        break
                else:
                    if y > z:
                        z = y
#                    print(y)
#   print()
    print(z)
                
